package com.corpdata.system.org.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.corpdata.system.org.entity.Dept;
import com.corpdata.system.org.service.DeptService;
import com.corpdata.common.base.BaseController;
import com.corpdata.common.result.Result;
import com.corpdata.common.result.DataGrid;

/**
 * 
 * 
 * @author zealon
 * @email zealon@126.com
 * @date 2018-04-24 17:21:04
 */
 
@Controller
@RequestMapping("/org/dept")
public class DeptController extends BaseController{

	@Autowired
	private DeptService deptService;
	
	//列表页面
	@GetMapping("/list")
	public String list(Model model, HttpServletRequest request){
	    return "org/dept/dept";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public DataGrid<Dept> getList(DataGrid dt){
		if (null == dt) {
            return null;
        }
		return deptService.selectDataGrid(dt);
	}
	
	//新增页面
	@GetMapping("/toadd")
	public String toAdd(){
	    return "org/dept/dept_add";
	}
	
	//新增数据
	@ResponseBody
	@PostMapping(value = "/add")
	public Result add(Dept dept) {
		if (null == dept) {
            return null;
        }
		return deptService.insert(dept);
	}

	//编辑页面
	@GetMapping("/toedit/{id}")
	public String toEdit(@PathVariable("id") String id,Model model){
		Dept dept = deptService.selectById(id);
		model.addAttribute("dept", dept);
	    return "org/dept/edit";
	}
	
	//编辑保存数据
	@ResponseBody
	@RequestMapping("/edit")
	public Result update(Dept dept){
		return deptService.update(dept);
	}
	
	//删除
	@ResponseBody
	@PostMapping("/delete")
	public Result delete(String id){
		return deptService.delete(id);
	}
	
	//批量删除
	@PostMapping("/batchdelete")
	@ResponseBody
	public Result batchDelete(@RequestParam("ids[]") String[] ids){
		return deptService.batchDelete(ids);
	}
	
}
